import 'package:app/components/index.dart';
import 'package:app/util/SecureStorage.dart';
import 'package:flutter/material.dart';

class Mine extends StatefulWidget{

  final String? userName;

  const Mine({super.key, this.userName});

  @override
  State<Mine> createState() => _MineState(userName);

}

/// 我的
class _MineState extends State<Mine>{

  final String? userName;

  _MineState(this.userName);

  /// 退出
  void logOut(){
    Confirm.of(context).show('确定要退出么', (){
      SecureStorage.of().remove('token');
      Navigator.pushNamed(context, '/');
    });
  }

  /// 跳转
  void go(path){
    Navigator.of(context).pushNamed(path);
  }


  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor:const Color.fromARGB(255, 245, 245, 245),
      body: Column(
        children: [
          Expanded(
              child: Column(
                children: [
                  Padding(
                    padding:const EdgeInsets.only(top: 20),
                    child: Container(
                      height: 120,
                      width: double.infinity,
                      color: const Color.fromARGB(255, 255, 255, 255),
                      child: Padding(
                        padding:const EdgeInsets.only(left: 10, right: 10),
                        child: Row(
                          children: [
                            Circular(
                                width: 80,
                                height: 80,
                                backgroundColor: Colors.grey,
                                child: const Icon(Icons.person, size: 60, color: Colors.white,)
                            ),
                            const Padding(
                              padding: EdgeInsets.only(left: 10),
                              child: Text("用户名：", style: TextStyle(fontSize: 15, fontWeight: FontWeight.w600),),
                            ),
                            Padding(
                              padding: const EdgeInsets.only(left: 2),
                              child: Text(userName??'', style: const TextStyle(fontSize: 14),),
                            )
                          ],
                        ),
                      ),
                    ),
                  ),
                  Padding(
                      padding: const EdgeInsets.only(top: 10),
                      child: Jump(label: '账号安全', context: context, onTap: ()=>{go("/password")},)
                  ),
                  // Padding(
                  //     padding: const EdgeInsets.only(top: 10),
                  //     child: Jump(label: '关于软件', context: context, onTap: ()=>{go("/about")},)
                  // ),
                ],
              )
          ),
          Column(
            children: [
              CustomButton(context: context, text: '切换账号', onTap: ()=>{go("/switch-account")},),
              CustomButton(context: context, text: '退出登录', onTap: logOut)
            ],
          )
        ],
      ),
    );
  }
  
}